- 1400/03/12
- 0
- 337
مشکل عدم اجرای سرویس نوشته شده
بنده یک سرویس نوشتم برای تماس با ما
using Application.Interfaces.Contexts;
using AutoMapper;
using Common.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Application.Services.ContactUs
{
public interface IContactUsService
{
ResultDto<RequestContactUsDto> Execute(RequestContactUsDto requestContactUsDto);
}
public class ContactUsService : IContactUsService
{
public IDataBaseContext _Context;
public IMapper _Mapper;
public ContactUsService(IDataBaseContext Context, IMapper Mapper)
{
_Context = Context;
_Mapper = Mapper;
}
public ResultDto<RequestContactUsDto> Execute(RequestContactUsDto requestContactUsDto)
{
var model = _Mapper.Map<Domain.Contact.ContactUs>(requestContactUsDto);
_Context.ContactUs.Add(model);
_Context.SaveChanges();
return new ResultDto<RequestContactUsDto>
{
IsSuccess = true,
Message = $"موضوع {model.Subject} با موفقیت در سیستم ثبت شد",
Data = _Mapper.Map<RequestContactUsDto>(model)
};
}
}
public class RequestContactUsDto
{
public string Name { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public string Subject { get; set; }
public string Description { get; set; }
}
}
حال در stratup پروژه اضافه کردم
#region Mapper
services.AddAutoMapper(typeof(ContactUsMappingProfile));
#endregion
#region Add Services
services.AddScoped<IContactUsService, ContactUsService>();
#endregion
اما در زمان اجرا با این خطا رو به رو میشم
System.AggregateException: 'Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Application.Services.ContactUs.IContactUsService Lifetime: Scoped ImplementationType: Application.Services.ContactUs.ContactUsService': Unable to resolve service for type 'Application.Interfaces.Contexts.IDataBaseContext' while attempting to activate 'Application.Services.ContactUs.ContactUsService'.)'
- 1400/03/12
آیا سرویس IDataBaseContext را هم در ioc ثبت کرده اید؟
احتمالا این سرویس را ثبت نکرده اید
- 1400/03/12
بله حق باش شما بود ، نمی دونم بعد از این همه تاکیدات موکد شما در فیلمها مبنی بر رعایت این مورد چرا باز دچار این اشتباه شدم...
با تشکر
پاسخی برای این باگ ارسال کنید
لطفا کدها را درون قطعه کد ارسال نمایید
برای ارسال پاسخ باید وارد حساب کاربری خود شوید
ورود به حساب کاربری